<?php namespace Admin\Models;
use \Laravel\Database\Eloquent\Model as Eloquent,
	Datagrid as Datagrid,
	Admin\Models\Navigation\Link as Link;
class Video extends Eloquent {

	public static $timestamps = true;
	public static $table = 'video';
	public static $key = 'vidid';

	public static function uploadVideo($input){

		$video = new Video;
		$video->fill($input);
		$video->save();

	}

    public static function listvideo(){
        
        $vidlist = Video::all();

        $arrayVideo = array();

        foreach ($vidlist as $value) {

            $arrayVideo[$value->vidid] = $value->vidtitle;

        }

        return $arrayVideo;
    }

    public static function listAvailvideo(){
        
        $vidlist = Video::all();

        $arrayVids = array();

        foreach ($vidlist as $value) {

            $regnav = Link::where('modulpageid','=',$value->vidid)->get();

            if(empty($regnav)){
                $arrayVids[$value->vidid] = $value->vidtitle;
            }
        }

        return $arrayVids;
    }

    public static function listAllVideo(){

        $allUser = Video::all();

        $datagrid = new Datagrid;
        $datagrid->setFields(array('vidtitle' =>'Title'));
        $datagrid->setFields(array('vidpath' =>'Directory'));
        $datagrid->setTable('video','table table-bordered table-hover table-striped table-condensed');
        $datagrid->build($allUser,'userid');

        return $datagrid->render();

    }

}